#!/bin/bash
#mysql安装
main_path=/usr/local/
install_path=/usr/local/mysql-5.7.24-linux-glibc2.12-x86_64

#判断mysql是否安装(rpm、source)
check_fun()
{ # 
service mysql stop
rpm_name=`rpm -aq |grep mysql-server`
        if [ ! $rpm_name ];then
                echo "开始检测源码包是否安装,请稍等......"
                        if [ -d $install_path ];then
                                echo "源码:$install_path目录存在,开始卸载."
				uninstall_fun                                
                        else
                                echo "本机未安装任何mysql程序..."
				exit 0
                        fi

        else
                echo -n "rpm mysql已安装,是否删除?[yes|no]"
                read select
                        if [ $select = yes ];then
                                rpm -ev $rpm_name --nodeps
                                rm -rf /var/log/mysqld.log
                                check_fun
                        else
                                exit 0
                        fi
        fi
}
uninstall_fun() #
{
cd $main_path
echo "当前目录 $PWD"
echo "delete $install_path"
rm -rf $install_path
rm -rf /usr/local/mysql

echo 'delete config ....'
rm -f /etc/my.cnf
rm -f /etc/init.d/mysql
}

main()
{
echo "#***********************************#"
echo "# 欢迎使用mysql卸载脚本 #"
echo "# Copyright 2018 by anyeway #"
echo "#***********************************#"
sleep 3
#开始执行，调用检测函数
check_fun
}
main
exit 0
